package com.rc.web.controller;

import com.rc.common.util.JsonUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;

@RestController
@RequestMapping("/menu")
@Api(tags = "后台管理路由")
public class MenuController {
    private final List<String> routes;

    public MenuController(@Value("${routes-path}") Resource resource) throws IOException {
        try (InputStream inputStream = resource.getInputStream()) {
            String s = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
            routes = JsonUtil.toObj(s, List.class);
        }
    }

    @GetMapping("/routes")
    @ApiModelProperty("获取所有路由")
    public List<String> getRoutes() {
        return this.routes;
    }
}
